<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>修改密码</title>
    <!-- 基本框架 -->
    <link rel="stylesheet" href="../../../css/common.css">
    <script src="../../../script/vue.min.js" type="text/javascript"></script>
    <script src="../../../script/frame.js" type="text/javascript"></script>
    <script src="../../../script/baseConfig.js" type="text/javascript"></script>
    <script src="../../../script/utils.js" type="text/javascript"></script>
    <script src="../../../script/common.js" type="text/javascript"></script>
    <style>
      body{background:#FFF;}
    </style>
</head>
<body>
    <div id="app" v-cloak>
        <div id="container">
            <div class="user-back" @click="api.closeWin()">
                <img src="../../../image/icons/left.png" />
            </div>
            <div class="user-content">
                <h3 class="user-title">修改密码</h3>
                <div class="user-input">
                    <input type="password" v-model="old_passwd" placeholder="请输入原密码" />
                </div>
                <div class="user-input">
                    <input type="password" v-model="new_passwd" placeholder="请输入新密码" />
                </div>
                <div class="user-input">
                    <input type="password" v-model="repeat_passwd" placeholder="确认新密码" />
                </div>
                <button @click="onSubmit" class="user-btn public-button">立即修改</button>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        apiready = function() {
            var app = new Vue({
                el:'#app',
                data:{
					iosTest:false,
                    old_passwd: '',
                    new_passwd: '',
                    repeat_passwd: '',
                },
                methods:{
                    validate: function(){
                        var status = true;
                        var msg = [];
                        if(this.old_passwd == ''){
                            msg.push('原密码');
                            status = false;
                        }
                        if(this.new_passwd == ''){
                            msg.push('新密码');
                            status = false;
                        }
                        if(this.repeat_passwd == ''){
                            msg.push('确认密码');
                            status = false;
                        }
                        if(!status){
                            $.toast(msg.join('、')+'不能为空');
                            return false;
                        }
                        if(this.new_passwd != this.repeat_passwd){
                            $.toast('两次输入的新密码不一致，请重新输入');
                            return false;
                        }
                        return status;
                    },
                    onSubmit: function(){
                        if(!this.validate()){
                            return false;
                        }
                        var _this = this;
                        $.ajax({
                            url: '/user/info/change',
                            method: 'post',
                            load: true,
                            data: {
                                old_passwd: md5(_this.old_passwd),
                                new_passwd: _this.new_passwd
                            },
                            success: function(res){
                                $.alert('密码修改成功', function(){
                                    api.closeWin();
                                });
                            }
                        });
                    }
                },
                mounted(){
					$.initJs(this);
                }
            });
        }
    </script>
</body>
</html>
